Exp=M
ModuleFileName=SoftKey.cs
@end
                                        
//´칤Զɣѡģ顱
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

	/// <summary>
	/// </summary>
	public class softkey
	{
		[DllImport ("ClientKeyDll.dll")]
		public static extern  int FindPort_3(string filename,int start,  StringBuilder OutKeyPath);
		[DllImport ("ClientKeyDll.dll")]
		public static extern  int FindPort_4(string filename,int start, string HKey,string LKey, StringBuilder OutKeyPath);
		[DllImport ("ClientKeyDll.dll")]
		public static extern  int Cal_2(string filename,int start, int pos,ref short a,ref short b,ref short c,ref short d, string KeyPah,int cycle);
		[DllImport ("ClientKeyDll.dll")]
		public static extern  int CalculateEx_3(string filename,int start, int pos,ref short a,ref short b,ref short c,ref short d, string KeyPah,int cycle);
		[DllImport ("ClientKeyDll.dll")]
		public static extern  int E_Ex_3(string HKey,string LKey,string filename, string filename_lll,string KeyPah);
		[DllImport ("ClientKeyDll.dll")]
        public static extern int GetIDVersionEx(ref int ID, ref short version, string KeyPah);
		[DllImport ("ClientKeyDll.dll")]
        public static extern int YReadEx(int Address, ref byte OutData, string KeyPah);
		[DllImport ("ClientKeyDll.dll")]
        public static extern int YWriteEx(byte OutData, int Address, string KeyPah);
		[DllImport ("ClientKeyDll.dll")]
        public static extern int ReadString([In, Out]byte[] OutString, int Address, int vlen, string KeyPah);
		[DllImport ("ClientKeyDll.dll")]
		public static extern  int FindPort(int start, StringBuilder OutKeyPath);
		[DllImport ("ClientKeyDll.dll")]
        public static extern int WriteString(string OutString, int Address, string KeyPah);
		[DllImport ("ClientKeyDll.dll")]
        public static extern int E_Dec_6(string HKey, string LKey, byte[] array_ele2, [In, Out] byte[] out_array, string KeyPah);
        [DllImport("ClientKeyDll.dll")]
        public static extern int CalculateEx_2(byte[] array_ele, ref short a, ref short b, ref short c, ref short d, string KeyPath_2, int mylen, int cycle);
		[DllImport ("ClientKeyDll.dll")]
		public static extern  int  ConnectServer (string servername, int port);
		[DllImport ("ClientKeyDll.dll")]
		public static extern  int  DisconnectServer ();
		[DllImport ("ClientKeyDll.dll")]
		public static extern  void  AutoDisConnect(uint timer,bool biao);
		private static int LastError;
		private static string KeyPath ;
		private string E_Hkey, E_Lkey;
		public softkey()
		{
			LastError = 0; //ʼΪ޴
		}
		//'ServerConnect
		//'Ŀģӷ
		//'1servername ҪӵķƻIPַ
		//'2port Ӷ˿,˿ںſԶ
		//'ؽ0ʾɹӷʾʧ
		//'ע⣺ʹκκ֮ǰһҪȵøúini֮ǰڳ˳ʱмһҪʹDisConnectServerϿ
		public int ServerConnect(string servername, int port )
		{
			LastError=ConnectServer(servername,port);
			if (LastError!=0 ) 
			{
		  		MessageBox.Show( "ӷ򣬴Ϊ" + LastError.ToString());
			}
			AutoDisConnect(60000, true); //ڳʱԶϿЧӣʱʱΪ60
			return LastError;
		}

		//'ServerDisConnect
		//'ĿģϿ
		//'ؽ0ʾɹϿʾʧ
		//'ע⣺ڳ˳ʱмһҪʹDisConnectServerϿ
		public int ServerDisConnect()
		{
		      return DisconnectServer();
		}
		//YGetLastError
		//ĿģȡĴ룬Ϊ0ʾûд
		//ؽĴ
		public  int YGetLastError()
		{
			return LastError;
		}

		 //ȡָеȨ
        public bool F_ReadKey() 
        {
        byte OutData=0 ;E_Hkey ="";E_Lkey ="";
        int n ;
        for(n=0;n<4;n++)
        {
          if( YReadEx(n, ref OutData, KeyPath) != 0 ) return false;
            E_Hkey = OutData.ToString("X2") + E_Hkey;
        }
        for(n=4;n<8;n++)
        {
          if (YReadEx(n, ref OutData, KeyPath) !=0) return false;
            E_Lkey = OutData.ToString("X2") + E_Lkey;
        }
        return true;
        }

		#INI#
		#Ini_2#
		#Ystrcat#
		#YCompareString#
		#Ystrcpy#
		#YAdd#
		#YSetValue#
		#YDivide#
		#Ymultiply#
		#YDecrease#
		#compare#
		#CheckKey#
		#Yor#
		#YAnd#	
		
	}

